/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>Project: app2022 - T30
 * <p>Powered by webrx On 2022-02-08 09:47:48
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T30 {
    AtomicInteger count = new AtomicInteger();
    //int count = 0;
    CountDownLatch latch = new CountDownLatch(100);

    public static void main(String[] args) throws InterruptedException {
        var t = new T30();
        long ss = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            new Thread(t::m, "thread-" + i).start();
        }

        try {
            //在100线程全部结束后，再向执行代码
            t.latch.await();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(t.count.get());
        //System.out.println(t.count);
        System.out.println(System.currentTimeMillis() - ss);
    }

    void m() {
        for (int i = 0; i < 10000; i++) count.getAndIncrement();
        //for (int i = 0; i < 10000; i++) count++;
        latch.countDown();
    }
}
